<?php

class CepController extends Controller{

	public function __construct(){
		header('Access-Control-Allow-Origin: *');
	}

	/**
	 * @url GET rest/cep/get
	 * @protected
	 */
	public function getEnderecoPorCep() {
		$dados = Uri::getPOST('json');
    $cep = $dados->cep;
		$cep = str_replace('.', '', $cep);
    $cep = str_replace('-', '', $cep);
    if(strlen($cep)==8)
    {
  		$model = new CepModel();
  		$result = $model->getEnderecoPorCep($cep);
    }
		if(!is_null($result)){
			echo json_encode($result);
		}
    else {
      echo json_encode(0);
    }
	}
}

?>